<?php

namespace App\ModelFilters;

use App\Models\DocumentTag;
use Carbon\Carbon;
use EloquentFilter\ModelFilter;

class DocumentFilter extends ModelFilter
{
    /**
    * Related Models that have ModelFilters as well as the method on the ModelFilter
    * As [relationMethod => [input_key1, input_key2]].
    *
    * @var array
    */
    public $relations = [];

    public function categoryId($v) {
        return $this->related('category', 'categoryId', $v);
    }

    public function title($v) {
        return $this->where('title', 'like', '%'.$v.'%');
    }

    public function province($v) {
        return $this->related('category', 'province', 'like', '%'.$v.'%');
    }

    public function tag($v) {
        return $this->related('tag', 'tagId', $v);
    }

    public function free($v) {
        return $this->where('amount', '>', 0);
    }
}
